home *** CD-ROM | disk | FTP | other *** search
- /*
- File: "how to call AutoPay.c"
-
- Last updated 9/6/95
-
- This file implements a simple application demonstrating how to use
- Digital Money's AutoPay™ code resource in your own application.
-
- This source code should run unmodified on both MetroWerks CodeWarrior C/C++
- and Symantec Think C compilers. Pascal development environments are also
- supported in supplementary files.
-
- What is this?: This is a meaningless app that puts up a window, waits
- for you to press a button, then launches the AutoPay
- module. When the AutoPay module is finished running,
- this mini-app puts up a final window. To actually
- run this, you'll need to include the DigitalMoney.π.rsrc
- resources in your project, along with the minimal
- resource set this mini-app uses. We've thoughtfully
- included those resources in the file "how to call.π.rsrc".
-
- To build this project: To build this project, include the "how to call.π.rsrc",
- the DigitalMoney.π.rsrc file, an ANSI C library
- (2-byte integers), and this source code file.
-
- Tech Support: If you're a developer and you need technical support, we'll
- be glad to help. We also welcome your comments, suggestions,
- and gripes.
-
- Technical support: (415) 833-0200
- digimoney@aol.com
- 71062.1251@compuserve.com
-
- Sales and info: (800) 210-5517
- Digital Money, Inc.
- Palo Alto, CA
- */
-
- #include "DMIdeveloper.h.c"
- #include <string.h>
-
- typedef pascal long (*DigiCodePtr) (long);
-
- void ToolBoxInit (void);
- void InitDigitalMoney(digiMonBlock *myDMCB);
- void DoDigitalMoney(digiMonBlock *dmiBlock);
-
- digiMonBlock gDMCB;
-
- /*
- Function: main
-
- Calls InitDigitalMoney() to fill in the struct that we pass to the Digital Money
- code resource. Calls DoDigitalMoney to execute the resource.
-
- Returns: Nothing.
- */
-
- void main (void)
- {
-
- // Set the app up
- ToolBoxInit();
- ParamText("\pPress OK to launch the AutoPay code resource.", "\p", "\p", "\p");
- NoteAlert(129, nil);
-
-
-
- // Fill in the Digital Money Control Block
- InitDigitalMoney(&gDMCB);
-
- // Execute the code resource using our DMCB
- DoDigitalMoney(&gDMCB);
-
- // Shut the app down
- ParamText("\pCode resource finished executing.", "\p", "\p", "\p");
- NoteAlert(129, nil);
- ExitToShell();
- }
-
- /*
- Function: ToolBoxInit
-
- The usual suspects.
-
- Returns: Nothing.
- */
-
- void ToolBoxInit(void)
- {
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- FlushEvents(everyEvent,0);
- TEInit();
- InitDialogs(0L);
- InitCursor();
- }
-
- /*
- Function: InitDigitalMoney
-
- Fills in the digiMonBlock struct with info appropriate for our sample product.
- Although this sample app doesn't do it, be sure to deallocate any memory allocated
- by this function after your call to DoDigitalMoney().
-
- Returns: Filled in struct in the myDMCB parameter
- */
-
- void InitDigitalMoney(digiMonBlock *myDMCB)
- {
- short i;
-
- // General settings
-
- strcpy(myDMCB->programName, "Testbed 1.0");
- myDMCB->returnSerialNum = 1; // 1=true; 0=false
- myDMCB->areAdditionalItemsForSale = 1; // 1=true; 0=false
- strcpy(myDMCB->programPassword, "tempPassword");
- strcpy(myDMCB->programID, "123456");
- strcpy(myDMCB->programSource, "CIS");
-
-
- // Security
-
- // This is a secret string of ascii characters used for encryption.
- // You should keep this key confidential, even among your own employees.
- // The string is comprised of visible ASCII characters - i.e. don't
- // use control characters. But punctuation is okay.
-
- strcpy(myDMCB->encodeMeth, "sampleEncodeUseYourOwn");
-
- // Screen Text
-
- // You can alter the text that appears on the top of each dialog box displayed
- // by Digital Money. Normally, Digital Money reads "styled text" resources
- // from your resource file, but if you want to change the text on the fly, so
- // to speak, you can just pass a pointer leading to the appropriate
- // text and style handle. Note that you must first initialize all 10 text pointers
- // to zero so that Digital Money can tell the difference between a zero pointer
- // (i.e. you don't want to replace the default text in the resource file) and a
- // non-zero pointer (you *do* want to change the text). See below for an example.
-
- for (i=0; i<=9; i++) {
- myDMCB->screenText[i] = 0;
- }
-
- // Next be sure to allocate memory for any pointer that you want Digital Money
- // to use. For instance, to change the text that appears on the opening screen,
- // set the screenText[0] pointer, like this:
-
-
- myDMCB->screenText[0] = NewPtr(200);
- myDMCB->screenText[0] = "Digital Money is embedded in a test application.\r
- Below, select how you want to pay.";
- myDMCB->textSize[0] = 10;
- myDMCB->textFont[0] = applFont;
-
-
- // ...for a complete list of which array item corresponds to which dialog,
- // see printed docs.
-
- // The users name
-
- // If you already know the users name for some reason, you should send it
- // to the DM Module, so that DM doesn't have to ask the user for it. If you
- // don't know it, then **be sure** to set the usersName string to null. In
- // any case, if the user successfully completes enough of the DM transaction,
- // his name will be returned to you in this string, should you want to use it,
- // for registration splash screens or whatever.
-
- strcpy(myDMCB->usersName, ""); // I don't know it, so it to null!
-
-
- // Software "switches"
-
- // AutoPay is continually being upgraded to add new features. You can turn new
- // features on and off by using a series of software "switches", which are set
- // through the "privateKey" field. The format of this field is: the asterisk
- // character ('*') followed by a series of 1's and 0's representing whether a
- // a switch (and thus a particular feature) is turned on or off. Currently you
- // can access two software switches, but six more are slated for future use.
- //
- // The format is:
- //
- // Character Description
- // ========= ===========
- // 0 always "*"
- // 1 0 = voice telephone ordering is selectable by the user
- // 1 = voice telephone ordering is disabled
- // 2 0 = no long product descriptions are avaiable
- // 1 = long product descriptions are avaiable starting at
- // TEXT resource 3040 (description of catalogItem[0])...
- // 3=8 For future use.
-
- strcpy(myDMCB->privateKey, "*00000000");
-
-
- // Your Product Catalog
-
- // Product names are generally short.
- // If you want to include "long" product descriptions, use the software switch
- // below and be sure to include one TEXT resource for every product in your
- // catalog, starting with resource #3040 (for catalogItem[0]). See the Manual
- // Addendum for more info.
-
- myDMCB->numItemsInCatalog = 3;
-
- // first, initialize pointers for each item in catalog
- // notice first item is item #0
-
- for (i= 0; i <= myDMCB->numItemsInCatalog - 1; i++) {
- myDMCB->catalogItem[i] = (catalogItemType *)NewPtr(sizeof(catalogItemType));
- }
-
-
- strcpy(myDMCB->catalogItem[0]->name, "Register Testbed 1.0");
- // registration items (if the item to be bought is the actual program in
- // which AutoPay is embedded), have product codes that start with 9
- strcpy(myDMCB->catalogItem[0]->prodCode, "90001");
- myDMCB->catalogItem[0]->minPurchase = 1;
- myDMCB->catalogItem[0]->maxPurchase = 1;
- myDMCB->catalogItem[0]->price = 15.50;
- myDMCB->catalogItem[0]->numVarCodes = 0;
- // Notice how you have to set shipping and handling charges (both domestic
- // and foreign) even if they're zero!
- myDMCB->catalogItem[0]->shUSA = 0;
- myDMCB->catalogItem[0]->shFOR = 0;
-
- strcpy(myDMCB->catalogItem[1]->name, "Digital Money tee-shirt");
- // physical goods that need to be delivered to the purchaser have product codes
- // that start with 7
- strcpy(myDMCB->catalogItem[1]->prodCode, "70002");
- myDMCB->catalogItem[1]->minPurchase = 1;
- myDMCB->catalogItem[1]->maxPurchase = 10;
- myDMCB->catalogItem[1]->price = 20;
- myDMCB->catalogItem[1]->numVarCodes = 2;
- strcpy(myDMCB->catalogItem[1]->varCode1, "LARGE");
- strcpy(myDMCB->catalogItem[1]->varCode2, "X-LARGE");
- myDMCB->catalogItem[1]->shUSA = 4;
- myDMCB->catalogItem[1]->shFOR = 10.50;
-
- strcpy(myDMCB->catalogItem[2]->name, "Upgrade from Testbed 0.9");
- // software upgrades have product codes that start with 8
- strcpy(myDMCB->catalogItem[2]->prodCode, "80003");
- myDMCB->catalogItem[2]->minPurchase = 1;
- myDMCB->catalogItem[2]->maxPurchase = 1;
- myDMCB->catalogItem[2]->price = 5;
- myDMCB->catalogItem[2]->numVarCodes = 0;
- myDMCB->catalogItem[2]->shUSA = 0;
- myDMCB->catalogItem[2]->shFOR = 0;
-
-
- // preselect items to be purchased
- // explanation: when the Digital Money module takes control of
- // the user interface, what items do you want to be preselected
- // for purchase by the user? If nothing, then set the following to 0.
-
- myDMCB->numItemsPrepurchased = 1;
-
- // Notice how the data structure of the preselected item precisely matches
- // the associated item in the product catalog. Please be careful and do
- // the same!
-
- // The only exception is the "editable" flag, which can be set to false
- // on a pre-selected item, even if the catalog doesn't match this. This
- // means the user won't be able to remove or edit this preselected item.
-
- strcpy(myDMCB->prepurchaseItem[0].name, "Register Testbed 1.0");
- strcpy(myDMCB->prepurchaseItem[0].prodCode, "90001");
- strcpy(myDMCB->prepurchaseItem[0].varCode, "");
- myDMCB->prepurchaseItem[0].price = 15.50;
- myDMCB->prepurchaseItem[0].quantity = 1;
- myDMCB->prepurchaseItem[0].editable = 1; // 1=true; 0=false
- myDMCB->prepurchaseItem[0].minPurchase = 1;
- myDMCB->prepurchaseItem[0].maxPurchase = 1;
- myDMCB->prepurchaseItem[0].shUSA=0;
- myDMCB->prepurchaseItem[0].shFOR=0;
-
- }
-
- /*
- Function: DoDigitalMoney
-
- Loads the DigitalMoney code resource into memory, and executes it. This works
- for PowerPC or 68K apps.
-
- Returns: Nothing
- */
-
- void DoDigitalMoney(digiMonBlock *dmiBlock)
- {
- UniversalProcPtr resProcUPP;
- ProcInfoType theProcInfo;
- Handle resHandle;
- OSErr result;
-
- resHandle = Get1Resource('CODE', 60);
- HLockHi(resHandle);
-
- #if defined(powerc) || defined (__powerc) || GENERATINGPOWERPC
-
- /*
- For PowerPC machines: The AutoPay resource is 68K, so if we're
- generating a PowerMac app call it from the Mixed Mode Manager
- */
- theProcInfo = kPascalStackBased | STACK_ROUTINE_PARAMETER
- (1, SIZE_CODE(sizeof(long)));
- resProcUPP = NewRoutineDescriptor((ProcPtr)*resHandle,
- theProcInfo, kM68kISA);
- CallUniversalProc(resProcUPP, theProcInfo, (long)dmiBlock);
- DisposeRoutineDescriptor(resProcUPP);
-
- #else
-
- /*
- For 68K machines, call it the old fashioned way
- */
- ((DigiCodePtr) *resHandle) ((long) dmiBlock);
-
-
- #endif
-
- HUnlock(resHandle);
- ReleaseResource(resHandle);
- }
-